package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.BotanyFileDao;
import cn.topevery.garden.entity.po.BotanyFile;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 
 *
 * @author code-generate
 * @date 2021-08-26
 */
@Service
public class BotanyFileLogic extends BaseLogic<BotanyFile> {
    @Autowired
    BotanyFileDao botanyFileDao;

    @Override
    public BaseEntityDao<BotanyFile, Integer> getDao() {
        return botanyFileDao;
    }

    /**
     * 描述 获取列表.
     *
     * @param pid  父ID
     * @param type (1-基础植物，2-古树名木)
     * @return the list
     * @author wenzhao.lin
     * @created 2021 -08-26 16:37:48 Get list by pid list.
     */
    public List<BotanyFile> getListByPid(Integer pid, Integer type){
        return botanyFileDao.getListByPid(pid, type);
    }


    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        botanyFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param botanyFileList 实体
     */
    public void saveOrUpdate(String userId, Integer pId, List<BotanyFile> botanyFileList,Integer type){
        botanyFileDao.deleteById(pId);
        for(BotanyFile botanyFile : botanyFileList){
            botanyFile.setMainId(pId);
            botanyFile.setType(type);
            botanyFileDao.saveOrUpdate(userId,botanyFile);
        }
    }
}
